package init;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.biz.ConfigurationBiz;
import cn.biz.GoodsBiz;
import cn.biz.UserBiz;
import cn.entity.Brand;
import cn.entity.Configuration;
import cn.entity.Goods;
import cn.entity.User;

public class InitSystem {
	private ApplicationContext con = new ClassPathXmlApplicationContext("applicationContext.xml");
	private GoodsBiz goodsBiz = (GoodsBiz) con.getBean("goodsBiz");
	private UserBiz userBiz = (UserBiz) con.getBean("userBiz");
	private ConfigurationBiz configBiz = (ConfigurationBiz) con.getBean("configurationBiz");
	
	public static void main(String args[]){
		InitSystem is = new InitSystem();
		is.initSystem();
	}
	
	public void initSystem(){
		
		InitSystem is = new InitSystem();
		System.out.println("----初始化系统----");
		is.insertConfig(1,"用户类型","usertype","管理员","");
		is.insertConfig(2,"用户类型","usertype","用户","");
		
		is.insertConfig(3,"商品类型","goodtype","存储设备","");
		is.insertConfig(4,"商品类型","goodtype","处理器","");
		is.insertConfig(5,"商品类型","goodtype","计算机外设","");
		
		/*is.insertConfig(6,"厂商","manufacturer","西部数据(WD)");
		is.insertConfig(7,"厂商","manufacturer","希捷(SeaGate)");
		is.insertConfig(8,"厂商","manufacturer","东芝(Toshiba)");
		is.insertConfig(9,"厂商","manufacturer","三星(Samsung)");
		is.insertConfig(10,"厂商","manufacturer","金士顿(Kingston)");*/
		
		is.insertConfig(6, "订单状态", "orderstatus", "待付款","001");
		is.insertConfig(7, "订单状态", "orderstatus", "买家已付款，待发货","002");
		is.insertConfig(8, "订单状态", "orderstatus", "卖家已发货，待买家确认","003");
		is.insertConfig(9, "订单状态", "orderstatus", "已确认收货","004");
		is.insertConfig(10, "订单状态", "orderstatus", "已关闭","999");
	
		
		is.insertUser(1, "管理员", "admin", "123456","1");
		is.insertUser(2, "漆黑追迹者", "black", "123456","2");
		is.insertUser(3, "酱油之道", "david", "123456","3");
		
		is.insertGood(1, "【漆黑数码】西数黑盘 320GB 7200rpm 2.5英寸", 6, 2, 239.00f, "西数(WD)高速硬盘，64MB缓存，笔记本专用机械硬盘，漆黑数码出品", 800);
		is.insertGood(2, "【漆黑数码】希捷 500GB 7200rpm 2.5英寸", 7, 2, 359.00f, "希捷(SeaGate)高速硬盘，16MB缓存，笔记本专用机械硬盘，漆黑数码出品", 760);
		is.insertGood(3, "【漆黑数码】东芝 1TB 7200rpm 2.5英寸", 8, 2, 439.00f, "东芝(Toshiba)机械硬盘，32MB缓存，笔记本专用机械硬盘，漆黑数码出品", 560);
		is.insertGood(2, "【酱油电商】三星 840 SATA3 120GB SSD", 9, 3, 629.00f, "三星(Samsung) 840固态硬盘，适用于笔记本和台式机，酱油电商2016年最新上架", 360);
		is.insertGood(2, "【酱油电商】三星 840 PRO 128GB SSD", 9, 3, 1029.00f, "三星(Samsung) 840 PRO固态硬盘，适用于笔记本和台式机，酱油电商2016年最新上架", 390);
		
		System.out.println("----系统初始化完毕!----");
	}
	
	public void insertConfig(int id,String name,String nameEn,String value1,String value2){
		Configuration c = new Configuration();
		c.setId(id);
		c.setName(name);
		c.setNameEn(nameEn);
		c.setValue1(value1);
		c.setValue2(value2);
		configBiz.insertOrUpdate(c);
		System.out.println("---配置: 插入 "+name+" 完毕---");
	}
	
	public void insertUser(int id,String name,String username,String password,String type){
		User u = new User();
		u.setId(id);
		u.setName(name);
		u.setUsername(username);
		u.setPassword(password);
		u.setType(type);
		userBiz.insert(u);
		System.out.println("---用户: 插入 "+username+" 完毕---");
	}
	
	public void insertGood(int id,String goodsname,int brand,int seller,float price,String remark,int stock){
		Goods g = new Goods();
		Brand brandBrand= new Brand();
		User userUser=userBiz.getUserById(seller);
		g.setId(id);
		g.setGoodsname(goodsname);
		g.setBrand(brandBrand);
		g.setIsDelete(0);
		g.setUser(userUser);
		g.setPrice(price);
		g.setRemark(remark);
		g.setStock(stock);
		goodsBiz.insert(g);
		System.out.println("---商品: 插入 "+goodsname+" 完毕---");
	}
}
